#!/bin/busybox sh

. /functions

mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys

echo 0 > /proc/sys/kernel/printk

clear

einfo "Loading kernel $(uname -r)"

ebegin "Waiting for the root LUKS header"
waitforhead
eend

ebegin "Mounting the header"
mount -o ro UUID=1131c013-1a12-4d16-9353-e6c08af98f6a /mnt/header || rescue_shell "Failed to mount the header partition"
eend

ebegin "Unlocking the LUKS header"
echo ""
cryptsetup open --tries 5 --header /mnt/header/header.img /dev/sda main || rescue_shell "Failed to open /dev/sda2"
eend

ebegin "Mouning root"
mount -o ro,subvol=@root /dev/mapper/main /mnt/root || rescue_shell "Failed mounting root"
eend

umount /mnt/header
umount /proc
umount /sys
umount /dev

exec switch_root /mnt/root /sbin/init

